<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        var arr = [1,44,23,5,9,55,12];
        var num = 10;
        function quickSort(arr){
            var arr = arr;
            if(arr.length <= 1){ 
                return arr
            }
            var middleIdx = Math.floor(arr.length / 2); //中间值下标
            var middleVal = arr[middleIdx]; //中间值
            arr.splice(middleIdx,1);
            var left = [];
            var right = [];
            for (var i = 0; i < arr.length; i++) {
                if (middleVal > arr[i]) {
                    left.push(arr[i])
                }else{
                    right.push(arr[i])
                }
            }
            return quickSort(left).concat(middleVal,quickSort(right));
        };
        
        // [1,5,44,23,9,55,12];
        // [44,23,55,12]
        // [12,23,44,55]
        // 
        // console.log(arr)
        // // arr.map(function(v,i,arr){
        // //     console.log(v)
        // //     console.log(i)
        // //     console.log(arr)
        // // })

        // for( var i in arr){
        //     console.log(i)
        // }
        // console.log(quickSort(arr).reverse());
        // console.log(arr.sort(function(a,b){
        //     return a - b;
        // }))
        // console.log(Array.isArray([]));
        // console.log([] instanceof Array);

        // var linar = ['小明','校长',"老师"];
        // console.log(linar.indexOf("校长")); //查找下标 找不到 - 1
        // console.log(arr.findIndex(function(v){
        //      return  v > 30
        // }))
        

        // 高级方法reduce
        var arr3 = [3,4,5,22,6];
        var arr4 = [{name:"新品上衣",price:20},{name:"新品裤子",price:30}]
        var num = arr4.reduce(function(sum,v,i){
            return sum+v.name
        },"")
        console.log(num)

        


        //filter 过滤
        var flLen = arr3.filter(function(v,i){
           return v > 4
        })
        console.log(flLen)
        
    </script>
</body>
</html>